﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TreaShares.Backoffice.Controlers;
using Telerik.Web.UI;

namespace TreaShares.Backoffice.User
{
    public partial class Transactions : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack) 
            {
                foreach (object col in this.RadGrid1.Columns)
                {
                    if (col is GridBoundColumn)
                    {
                        GridBoundColumn gbc = col as GridBoundColumn;
                        if (gbc.ColumnType == "GridDateTimeColumn")
                        {
                            gbc.DataFormatString = this.Master.OrgBasicInfo.UserSettings.DateFormat;
                        }
                        else if (gbc.ColumnType == "GridNumericColumn")
                        {
                            gbc.DataFormatString = this.Master.OrgBasicInfo.UserSettings.ThousandsAndDecimalSeparator;
                        }
                    }
                }
            }
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            RadGrid1.MasterTableView.ExportToCSV();
        }
        protected void Button4_Click(object sender, EventArgs e)
        {
            RadGrid1.MasterTableView.ExportToPdf();
        }
        protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "InitInsert")
            {
                Response.Redirect("~/Backoffice/User/TransactionsAdd.aspx");
            } 
        }

        protected void btnTransactionSummary_Click(object sender, EventArgs e)
        {
            DateTime from = DateTime.Parse( this.txtSummaryFrom.Text);
            DateTime to = DateTime.Parse( this.txtSummaryTo.Text);
            TransactionManager transactionManager = new TransactionManager();
            var results = transactionManager.SelectStockSummaryPosition(this.Master.OrgBasicInfo.Id, from, to);
            rgTransactionSummary.DataSource = results;
            rgTransactionSummary.DataBind();
        }

    }
}